"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var invariant_1 = require("invariant");
var bggood_store_utils_1 = require("bggood-store-utils");
/**
 * action操作方法
 *
 * @export
 * @class PromiseAction
 */
var PromiseAction = /** @class */ (function () {
    function PromiseAction(options) {
        options = options || {};
        return this;
    }
    PromiseAction.prototype.init = function (dispatch, type) {
        invariant_1.default(typeof dispatch === 'object', 'dispatch: dispatch should be a object');
        invariant_1.default(typeof dispatch.commit === 'function', 'dispatch.commit: dispatch.commit should be a function');
        invariant_1.default(typeof type === 'string', 'type: dispatch.commit should be a string');
        dispatch.commit(type);
        return this;
    };
    PromiseAction.prototype.set = function (dispatch, type, promise) {
        invariant_1.default(typeof dispatch === 'object', 'dispatch: dispatch should be a object');
        invariant_1.default(typeof dispatch.commit === 'function', 'dispatch.commit: dispatch.commit should be a function');
        invariant_1.default(typeof type === 'string', 'type: dispatch.commit should be a string');
        bggood_store_utils_1.observablePromise(promise, function (item) {
            dispatch.commit(type, item);
        });
        return this;
    };
    PromiseAction.prototype.commit = function (promise, callBackFunc) {
        bggood_store_utils_1.observablePromise(promise, function (item) {
            callBackFunc && callBackFunc(item);
        });
        return this;
    };
    return PromiseAction;
}());
exports.PromiseAction = PromiseAction;
